R Setup, Load Packages and Data
knitr::opts_chunk$set(comment=NA)
options(width = 70)
library(dplyr)
Warning: package 'dplyr' was built under R version 3.5.2
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(plotly)
Loading required package: ggplot2
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
library(rms)
Warning: package 'rms' was built under R version 3.5.2
Loading required package: Hmisc
Warning: package 'Hmisc' was built under R version 3.5.2
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Attaching package: 'Hmisc'
The following object is masked from 'package:plotly':
subplot
The following objects are masked from 'package:dplyr':
src, summarize
The following objects are masked from 'package:base':
format.pval, units
Loading required package: SparseM
Attaching package: 'SparseM'
The following object is masked from 'package:base':
backsolve
library(knitr)
Warning: package 'knitr' was built under R version 3.5.2
library(broom)
library(janitor)
library(tidyverse)
── Attaching packages ───────────────────────────────────────────────────────── tidyverse 1.2.1 ──
✔ tibble 2.1.1 ✔ purrr 0.3.2
✔ tidyr 0.8.3 ✔ stringr 1.4.0
✔ readr 1.3.1 ✔ forcats 0.4.0
Warning: package 'tibble' was built under R version 3.5.2
Warning: package 'tidyr' was built under R version 3.5.2
Warning: package 'purrr' was built under R version 3.5.2
Warning: package 'stringr' was built under R version 3.5.2
Warning: package 'forcats' was built under R version 3.5.2
── Conflicts ──────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ plotly::filter() masks dplyr::filter(), stats::filter()
✖ dplyr::lag() masks stats::lag()
✖ Hmisc::src() masks dplyr::src()
✖ Hmisc::summarize() masks dplyr::summarize()
ohdata <- read_csv("data/oh_counties_2017.csv") %>%
clean_names()
Parsed with column specification:
cols(
.default = col_double(),
state = col_character(),
county = col_character(),
h2oviol = col_character()
)
See spec(...) for full column specifications.
ohdata
# A tibble: 88 x 44
fips state county years_lost_rate sroh_fairpoor phys_days
<dbl> <chr> <chr> <dbl> <dbl> <dbl>
1 39001 Ohio Adams 10304 21.9 4.83
2 39003 Ohio Allen 7142 17.2 4.04
3 39005 Ohio Ashla… 6093 16.3 3.78
4 39007 Ohio Ashta… 9292 17.7 4.24
5 39009 Ohio Athens 7853 21.4 4.69
6 39011 Ohio Augla… 5587 13.1 3.4
7 39013 Ohio Belmo… 7935 17.2 4.03
8 39015 Ohio Brown 10157 16.6 4.02
9 39017 Ohio Butler 7737 15.8 3.79
10 39019 Ohio Carro… 7754 15.5 3.68
# … with 78 more rows, and 38 more variables: ment_days <dbl>,
# lbw_pct <dbl>, smoker_pct <dbl>, obese_pct <dbl>, food_env <dbl>,
# inactive_pct <dbl>, exer_access <dbl>, exc_drink <dbl>,
# alc_drive <dbl>, sti_rate <dbl>, teen_births <dbl>,
# uninsured <dbl>, pcp_ratio <dbl>, prev_hosp <dbl>, hsgrads <dbl>,
# unemployed <dbl>, poor_kids <dbl>, income_ratio <dbl>,
# associations <dbl>, pm2_5 <dbl>, h2oviol <chr>,
# sev_housing <dbl>, drive_alone <dbl>, age_adj_mortality <dbl>,
# dm_prev <dbl>, freq_phys_distress <dbl>,
# freq_mental_distress <dbl>, food_insecure <dbl>,
# insuff_sleep <dbl>, health_costs <dbl>, median_income <dbl>,
# population <dbl>, age65plus <dbl>, african_am <dbl>,
# hispanic <dbl>, white <dbl>, female <dbl>, rural <dbl>
p <- plot_ly(
ohdata, x = ~food_insecure, y = ~african_am,
hoverinfo= 'text',
text = ~paste("County:", county, '<br> % of Residents Who Are Food Insecure:', food_insecure,'<br> % of Residents Who Are African American:', african_am),
color = ~african_am, size = ~african_am) %>%
layout(
title = 'Examining Food Insecurity and Race -
State of Ohio County Health Rankings, 2017',
xaxis = list(title = "% of Residents Who Are Food Insecure"),
yaxis = list(side = 'left', title = '% of Residents Who Are African American'),
annotations = list(text = 'A trend is observed by county:
The greater the population density of African American
residents, the higher the percentage of food insecurity reported.',
font = list(size = 08),
showarrow = FALSE,
xref = 'paper', x = 0.1,
yref = 'paper', y = 0.7))
hide_colorbar(p)
No trace type specified:
Based on info supplied, a 'scatter' trace seems appropriate.
Read more about this trace type -> https://plot.ly/r/reference/#scatter
No scatter mode specifed:
Setting the mode to markers
Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
Warning: `line.width` does not currently support multiple values.